package activity;

/**
 * Created by Administrator on 2017/7/22.
 */

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.administrator.ci_edit.R;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import adapter.MyWorkAdapter;
import entity.MyWork;
import util.FileUtils;


public class MyWorkActivity extends AppCompatActivity {
    //private String[] data = {"长相思","钗头凤","点绛唇","蝶恋花","喝火令","贺新郎","木兰花","满江红","调笑令"};
    private List<MyWork> myWorkList = new ArrayList<MyWork>();

    // private JiangDatabaseHelper jiangDatabaseHelper;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        /*super.onCreate(savedInstanceState);
        setContentView(R.layout.actvity_poem_select);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(PoemSelectActivity.this,android.R.layout.simple_list_item_1,data);
        ListView listView=(ListView)findViewById(R.id.list_view);
        listView.setAdapter(adapter);*/
        initCipaiInfos();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mywork);
        MyWorkAdapter adapter = new MyWorkAdapter(MyWorkActivity.this, R.layout.mywork_item, myWorkList);
        ListView listView = (ListView) findViewById(R.id.mywork_list_view);
        listView.setAdapter(adapter);

        //点击listview中的一项的点击操作
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                //CipaiInfo cipaiInfo = cipaiInfoList.get(position);

                MyWork myWork = myWorkList.get(position);
                String path = FileUtils.WORK_DIR + myWork.getWorkname();
                path = FileUtils.pathTopath(path);
                String mywork = FileUtils.DerrickWannaReadFileAAA(path);
                Intent intent = new Intent();
                intent.putExtra("extra_mywork", mywork);
                intent.setClass(MyWorkActivity.this, activity.ZiHuaActivity.class);
                MyWorkActivity.this.startActivity(intent);

            }
        });

    }

    //用来My work数据
    private void initCipaiInfos() {
        File file = new File(FileUtils.WORK_DIR);
        if (file.isDirectory()) {
            File[] fileArray = file.listFiles();
            if (null != fileArray && 0 != fileArray.length) {
                for (int i = 0; i < fileArray.length; i++) {
                    MyWork mywork = new MyWork(fileArray[i].getName());
                    myWorkList.add(mywork);
                }

            }

        }
    }
}
